<template>
  <div class='search'>
    <f-form ref='form' :action='api.payment' :form-key='this.formItem.paymentId' handlerName='refundBondPaymentSaveHandler'>
      <f-form-item label='业务员'  disabled  name='saleManName' :value='formItem.saleManName' />
      <f-form-item label='退款金额' required dataType='number' name='amount' :max='formItem.refundAmount' type='number' :value='formItem.amount' />
      <f-form-item label='收款账户' placeholder='请选择收款账户' name='bankName' :readOnly='true' :required='true' :value.sync='formItem.bankName' :trigger-change='true'>
        <a-tooltip slot='addonBefore' placement='top' title='点击图标选择收款账户'>
          <a-icon type='team' style='cursor:pointer' @click='openSaleManBankModal' />
        </a-tooltip>
      </f-form-item>
      <f-form-item label='申请日期' required type='date' name='amountDate' :value='formItem.amountDate' />
      <f-form-item label='备注' type='textarea' name='remark' :value='formItem.remark' />
    </f-form>
    <select-sale-man-bank-modal ref='saleManBankModal' @onSelectChange='onSelectSaleManBankChange'></select-sale-man-bank-modal>
  </div>
</template>
<script>
import api from "../../js/api"
import SelectSaleManBankModal from "@/views/module/haiying/components/select_saleman_bank_modal"
import { commonMixins } from "@/core/mixins/commonMixins"
export default {
  name: "amountForm",
  props: {},
  mixins: [commonMixins],
  data() {
    return {
      api: Object.assign(api, this.api),
      selectIds:null,
      formItem: this.getFormItem()
    }
  },
  methods: {
    getFormItem() {
      return {
        depositId: "",
        refundAmount: 0,
        payAmount: 0,
        refundDate: null,
        remark: null
      }
    },

    //表单赋值
    setData(data) {
      this.$refs.form.resetFields()
      this.formItem = this.getFormItem()
      if (data && data.selectIds) {
        this.selectIds = data.selectIds;
        this.getRefundBondInfo()
      }
    },
    /**
     * 收款账户选择回调
     */
    onSelectSaleManBankChange(selectedRowKeys, selectedRows) {
      this.$refs.form.getForm().setFieldsValue({ "bankName": selectedRows[0].bankName })
      this.formItem.bankId = selectedRowKeys[0]
      this.$forceUpdate()
    },
    /**
     * 获取退保证金信息
     */
    getRefundBondInfo() {
      this.http.get(this, {
        url: this.api.payment.getRefundBondInfo,
        params: {
          selectIds: this.selectIds
        },
        success: (me, data) => {
          this.$nextTick(() => {
            this.formItem = data
            if (data.saleManName) {
              this.formItem.saleManName = data.saleManName
              this.formItem.bankName = data.bankName
              this.formItem.amount = data.customBondTakeAmount
              this.formItem.refundAmount = data.customBondTakeAmount
              this.formItem.saleManId = data.saleManId
              this.$refs.form.getForm().setFieldsValue({ "saleManName": data.saleManName })
              this.$refs.form.getForm().setFieldsValue({ "bankName": data.bankName })
              this.$refs.form.getForm().setFieldsValue({ "refundAmount": data.refundAmount })
            }
            this.$forceUpdate()
          })
        }
      })
    },
    //提交表单
    handleSubmit(callback) {
      this.$refs.form.submit({
        bankId: this.formItem.bankId,
        selectIds:this.selectIds
      }, callback)
    }
  },
  created() {
  },
  components: { SelectSaleManBankModal }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
